//
//  File.swift
//  
//
//  Created by Jiang Chencheng on 2024/9/10.
//

import Vapor


extension Request {
    
    static let authedUserKey = "authedUserKey"
    
    @available(*, deprecated, message: "不要再使用该方法啦")
    func getAuthedUser() async throws -> User {
        guard let user: User =  try await cache.get(Self.authedUserKey) else {
            throw BizError.userNotFound
        }
        return user
    }
    
    
    func getAuthedUserID() throws -> UUID {
        let sessionToken = try auth.require(SessionToken.self)
        let userID = sessionToken.userId
        return userID
    }
    
}
